home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / layout / nsICSSStyleRule.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  8KB  |  228 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* ***** BEGIN LICENSE BLOCK *****
  3.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4.  *
  5.  * The contents of this file are subject to the Mozilla Public License Version
  6.  * 1.1 (the "License"); you may not use this file except in compliance with
  7.  * the License. You may obtain a copy of the License at
  8.  * http://www.mozilla.org/MPL/
  9.  *
  10.  * Software distributed under the License is distributed on an "AS IS" basis,
  11.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12.  * for the specific language governing rights and limitations under the
  13.  * License.
  14.  *
  15.  * The Original Code is mozilla.org code.
  16.  *
  17.  * The Initial Developer of the Original Code is
  18.  * Netscape Communications Corporation.
  19.  * Portions created by the Initial Developer are Copyright (C) 1998
  20.  * the Initial Developer. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Daniel Glazman <glazman@netscape.com>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either of the GNU General Public License Version 2 or later (the "GPL"),
  27.  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38. #ifndef nsICSSStyleRule_h___
  39. #define nsICSSStyleRule_h___
  40.  
  41. //#include <stdio.h>
  42. #include "nsICSSRule.h"
  43. #include "nsString.h"
  44. #include "nsCOMPtr.h"
  45. #include "nsCSSProps.h"
  46. #include "nsCSSValue.h"
  47. #include "nsIAtom.h"
  48.  
  49. class nsIAtom;
  50. class nsCSSDeclaration;
  51. class nsICSSStyleSheet;
  52.  
  53. struct nsAtomList {
  54. public:
  55.   nsAtomList(nsIAtom* aAtom);
  56.   nsAtomList(const nsString& aAtomValue);
  57.   nsAtomList(const nsAtomList& aCopy);
  58.   ~nsAtomList(void);
  59.   PRBool Equals(const nsAtomList* aOther) const;
  60.  
  61.   nsCOMPtr<nsIAtom> mAtom;
  62.   nsAtomList*       mNext;
  63. };
  64.  
  65. struct nsAtomStringList {
  66. public:
  67.   nsAtomStringList(nsIAtom* aAtom, const PRUnichar *aString = nsnull);
  68.   nsAtomStringList(const nsString& aAtomValue, const PRUnichar *aString = nsnull);
  69.   nsAtomStringList(const nsAtomStringList& aCopy);
  70.   ~nsAtomStringList(void);
  71.   PRBool Equals(const nsAtomStringList* aOther) const;
  72.  
  73.   nsCOMPtr<nsIAtom> mAtom;
  74.   PRUnichar*        mString;
  75.   nsAtomStringList* mNext;
  76. };
  77.  
  78. #define NS_ATTR_FUNC_SET        0     // [attr]
  79. #define NS_ATTR_FUNC_EQUALS     1     // [attr=value]
  80. #define NS_ATTR_FUNC_INCLUDES   2     // [attr~=value] (space separated)
  81. #define NS_ATTR_FUNC_DASHMATCH  3     // [attr|=value] ('-' truncated)
  82. #define NS_ATTR_FUNC_BEGINSMATCH  4   // [attr^=value] (begins with)
  83. #define NS_ATTR_FUNC_ENDSMATCH  5     // [attr$=value] (ends with)
  84. #define NS_ATTR_FUNC_CONTAINSMATCH 6  // [attr*=value] (contains substring)
  85.  
  86. struct nsAttrSelector {
  87. public:
  88.   nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr);
  89.   nsAttrSelector(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunction, 
  90.                  const nsString& aValue, PRBool aCaseSensitive);
  91.   nsAttrSelector(const nsAttrSelector& aCopy);
  92.   ~nsAttrSelector(void);
  93.   PRBool Equals(const nsAttrSelector* aOther) const;
  94.  
  95.   PRInt32         mNameSpace;
  96.   nsIAtom*        mAttr;
  97.   PRUint8         mFunction;
  98.   PRPackedBool    mCaseSensitive;
  99.   nsString        mValue;
  100.   nsAttrSelector* mNext;
  101. };
  102.  
  103. struct nsCSSSelector {
  104. public:
  105.   nsCSSSelector(void);
  106.   nsCSSSelector(const nsCSSSelector& aCopy);
  107.   ~nsCSSSelector(void);
  108.  
  109.   nsCSSSelector& operator=(const nsCSSSelector& aCopy);
  110.   PRBool Equals(const nsCSSSelector* aOther) const;
  111.  
  112.   void Reset(void);
  113.   void SetNameSpace(PRInt32 aNameSpace);
  114.   void SetTag(const nsString& aTag);
  115.   void AddID(const nsString& aID);
  116.   void AddClass(const nsString& aClass);
  117.   void AddPseudoClass(const nsString& aPseudoClass, const PRUnichar* aString = nsnull);
  118.   void AddPseudoClass(nsIAtom* aPseudoClass, const PRUnichar* aString = nsnull);
  119.   void AddAttribute(PRInt32 aNameSpace, const nsString& aAttr);
  120.   void AddAttribute(PRInt32 aNameSpace, const nsString& aAttr, PRUint8 aFunc, 
  121.                     const nsString& aValue, PRBool aCaseSensitive);
  122.   void SetOperator(PRUnichar aOperator);
  123.  
  124.   PRInt32 CalcWeight(void) const;
  125.  
  126.   void ToString(nsAString& aString, nsICSSStyleSheet* aSheet,
  127.                 PRBool aAppend = PR_FALSE) const;
  128.  
  129. private:
  130.  
  131.   void AppendNegationToString(nsAString& aString);
  132.   void ToStringInternal(nsAString& aString, nsICSSStyleSheet* aSheet,
  133.                         PRBool aIsPseudoElem,
  134.                         PRIntn aNegatedIndex) const;
  135.  
  136. public:
  137.   PRInt32         mNameSpace;
  138.   nsCOMPtr<nsIAtom> mTag;
  139.   nsAtomList*     mIDList;
  140.   nsAtomList*     mClassList;
  141.   nsAtomStringList* mPseudoClassList; // atom for the pseudo, string for
  142.                                       // the argument to functional pseudos
  143.   nsAttrSelector* mAttrList;
  144.   PRUnichar       mOperator;
  145.   nsCSSSelector*  mNegations;
  146.  
  147.   nsCSSSelector*  mNext;
  148. };
  149.  
  150. /**
  151.  * A selector list is the unit of selectors that each style rule has.
  152.  * For example, "P B, H1 B { ... }" would be a selector list with two
  153.  * items (where each |nsCSSSelectorList| object's |mSelectors| has
  154.  * an |mNext| for the P or H1).  We represent them as linked lists.
  155.  */
  156. struct nsCSSSelectorList {
  157.   nsCSSSelectorList(void);
  158.   ~nsCSSSelectorList(void);
  159.  
  160.   /**
  161.    * Push a copy of |aSelector| on to the beginning of |mSelectors|,
  162.    * setting its |mNext| to the current value of |mSelectors|.
  163.    *
  164.    * The caller is responsible for updating |mWeight|.
  165.    */
  166.   void AddSelector(const nsCSSSelector& aSelector);
  167.  
  168.   /**
  169.    * Should be used only on the first in the list
  170.    */
  171.   void ToString(nsAString& aResult, nsICSSStyleSheet* aSheet);
  172.  
  173.   /**
  174.    * Do a deep clone.  Should be used only on the first in the list.
  175.    */
  176.   nsCSSSelectorList* Clone();
  177.  
  178.   nsCSSSelector*     mSelectors;
  179.   PRInt32            mWeight;
  180.   nsCSSSelectorList* mNext;
  181. };
  182.  
  183. // IID for the nsICSSStyleRule interface {00803ccc-66e8-4ec8-a037-45e901bb5304}
  184. #define NS_ICSS_STYLE_RULE_IID     \
  185. {0x00803ccc, 0x66e8, 0x4ec8, {0xa0, 0x37, 0x45, 0xe9, 0x01, 0xbb, 0x53, 0x04}}
  186.  
  187. class nsICSSStyleRule : public nsICSSRule {
  188. public:
  189.   NS_DEFINE_STATIC_IID_ACCESSOR(NS_ICSS_STYLE_RULE_IID)
  190.  
  191.   // null for style attribute
  192.   virtual nsCSSSelectorList* Selector(void) = 0;
  193.  
  194.   virtual PRUint32 GetLineNumber(void) const = 0;
  195.   virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
  196.  
  197.   virtual nsCSSDeclaration* GetDeclaration(void) const = 0;
  198.  
  199.   /**
  200.    * Return a new |nsIStyleRule| instance that replaces the current one,
  201.    * due to a change in the |nsCSSDeclaration|.  Due to the
  202.    * |nsIStyleRule| contract of immutability, this must be called if the
  203.    * declaration is modified.
  204.    *
  205.    * |DeclarationChanged| handles replacing the object in the container
  206.    * sheet or group rule if |aHandleContainer| is true.
  207.    */
  208.   virtual already_AddRefed<nsICSSStyleRule>
  209.     DeclarationChanged(PRBool aHandleContainer) = 0;
  210.  
  211.   virtual already_AddRefed<nsIStyleRule> GetImportantRule(void) = 0;
  212.  
  213.   // hooks for DOM rule
  214.   virtual nsresult GetCssText(nsAString& aCssText) = 0;
  215.   virtual nsresult SetCssText(const nsAString& aCssText) = 0;
  216.   virtual nsresult GetParentStyleSheet(nsICSSStyleSheet** aSheet) = 0;
  217.   virtual nsresult GetParentRule(nsICSSGroupRule** aParentRule) = 0;
  218.   virtual nsresult GetSelectorText(nsAString& aSelectorText) = 0;
  219.   virtual nsresult SetSelectorText(const nsAString& aSelectorText) = 0;
  220. };
  221.  
  222. nsresult
  223. NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult,
  224.                    nsCSSSelectorList* aSelector,
  225.                    nsCSSDeclaration* aDeclaration);
  226.  
  227. #endif /* nsICSSStyleRule_h___ */
  228.